package com.everyday.practice.leetCode;

public class Title33 {

    public static void main(String[] args) {
        int[] nums=new int[7];
        nums[0]=4;
        nums[1]=5;
        nums[2]=6;
        nums[3]=7;
        nums[4]=0;
        nums[5]=1;
        nums[6]=2;
        int search = search(nums, 0);
        System.out.println(search);
    }

    public static int search(int[] nums, int target) {
        int add=0;
        int targetIndex=-1;
        if (nums.length==1){
            if (nums[0]==target){
                return 1;
            }else {
                return -1;
            }
        }
        for (int i=0;i<nums.length-1;i++){
            if (nums[i]==target){
                targetIndex=i;
            }else if (nums[i+1]==target){
                targetIndex=i+1;
            }
            if (nums[i]>nums[i+1]){
                add=i+1;
            }
        }
        return targetIndex+add;
    }

}
